/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.ems.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.ems.entity.EmsCartHis;
import com.thinkgem.jeesite.modules.ems.service.EmsCartHisService;

/**
 * 购物车历史Controller
 * @author zad
 * @version 2018-01-25
 */
@Controller
@RequestMapping(value = "${adminPath}/ems/emsCartHis")
public class EmsCartHisController extends BaseController {

	@Autowired
	private EmsCartHisService emsCartHisService;
	
	@ModelAttribute
	public EmsCartHis get(@RequestParam(required=false) String id) {
		EmsCartHis entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = emsCartHisService.get(id);
		}
		if (entity == null){
			entity = new EmsCartHis();
		}
		return entity;
	}
	
	@RequiresPermissions("ems:emsCartHis:view")
	@RequestMapping(value = {"list", ""})
	public String list(EmsCartHis emsCartHis, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<EmsCartHis> page = emsCartHisService.findPage(new Page<EmsCartHis>(request, response), emsCartHis); 
		model.addAttribute("page", page);
		return "modules/ems/emsCartHisList";
	}

	@RequiresPermissions("ems:emsCartHis:view")
	@RequestMapping(value = "form")
	public String form(EmsCartHis emsCartHis, Model model) {
		model.addAttribute("emsCartHis", emsCartHis);
		return "modules/ems/emsCartHisForm";
	}

	@RequiresPermissions("ems:emsCartHis:edit")
	@RequestMapping(value = "save")
	public String save(EmsCartHis emsCartHis, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, emsCartHis)){
			return form(emsCartHis, model);
		}
		emsCartHisService.save(emsCartHis);
		addMessage(redirectAttributes, "保存已报课程成功");
		return "redirect:"+Global.getAdminPath()+"/ems/emsCartHis/?repage";
	}
	
	@RequiresPermissions("ems:emsCartHis:edit")
	@RequestMapping(value = "delete")
	public String delete(EmsCartHis emsCartHis, RedirectAttributes redirectAttributes) {
		emsCartHisService.delete(emsCartHis);
		addMessage(redirectAttributes, "删除已报课程成功");
		return "redirect:"+Global.getAdminPath()+"/ems/emsCartHis/?repage";
	}

}